#import "Category.h"

@implementation Category

@synthesize catId;
@synthesize name;

-(id)proxyForJson{
	return [NSDictionary dictionaryWithObjectsAndKeys:catId,@"id",name,@"name",nil];
}

+(Category*)fromString:(NSString *)s{
	SBJsonParser *parser = [SBJsonParser new];
	return [Category fromJsonObj:[parser objectWithString:s]];
}

+(Category*)fromJsonObj:(id)obj{
	Category* ret=[Category new];
	id t;

	t=[obj valueForKey:@"id"];
	if(t!=nil) ret.catId=t;
	else NSLog(@"warning: Category.fromJsonObj: missing category id");

	t=[obj valueForKey:@"name"];
	if(t!=nil) ret.name=(NSString *)t;
	else NSLog(@"warning: Category.fromJsonObj: missing category name");

	return ret;
}

-(void)dealloc{
	[catId release];
	[name release];
	[super dealloc];
}

@end
